<!DOCTYPE html><html lang="zh" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Echarts | 审陌</title><meta name="author" content="审陌"><meta name="copyright" content="审陌"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Echarts一、初始化项目123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869&lt;template&gt;    &lt;div id&#x3D;&quot;main&quot;&gt;&lt;&#x2F;d">
<meta property="og:type" content="article">
<meta property="og:title" content="Echarts">
<meta property="og:url" content="https://gitee.com/trial-street/shenmo.git/2023/10/27/echarts/index.html">
<meta property="og:site_name" content="审陌">
<meta property="og:description" content="Echarts一、初始化项目123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869&lt;template&gt;    &lt;div id&#x3D;&quot;main&quot;&gt;&lt;&#x2F;d">
<meta property="og:locale">
<meta property="og:image" content="https://gitee.com/trial-street/shenmo.git/img/echarts.png">
<meta property="article:published_time" content="2023-10-27T13:24:00.000Z">
<meta property="article:modified_time" content="2023-10-30T11:42:56.855Z">
<meta property="article:author" content="审陌">
<meta property="article:tag" content="Echarts">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/trial-street/shenmo.git/img/echarts.png"><link rel="shortcut icon" href="/shenmo/img/favicon.png"><link rel="canonical" href="https://gitee.com/trial-street/shenmo.git/2023/10/27/echarts/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/shenmo/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/shenmo/',
  algolia: undefined,
  localSearch: {"path":"/shenmo/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy Successful',
    error: 'Copy Error',
    noSupport: 'Browser Not Supported'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: 'Just now',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: 'Load More'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Echarts',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-10-30 19:42:56'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/shenmo/atom.xml" title="审陌" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/shenmo/img/fluid.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/shenmo/archives/"><div class="headline">Articles</div><div class="length-num">19</div></a><a href="/shenmo/tags/"><div class="headline">Tags</div><div class="length-num">19</div></a><a href="/shenmo/categories/"><div class="headline">Categories</div><div class="length-num">17</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/shenmo/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/shenmo/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/shenmo/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/shenmo/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 个人</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/shenmo/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/shenmo/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/shenmo/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/shenmo/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image: url('/shenmo/img/echarts.png')"><nav id="nav"><span id="blog-info"><a href="/shenmo/" title="审陌"><span class="site-name">审陌</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> Search</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/shenmo/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/shenmo/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/shenmo/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/shenmo/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 个人</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/shenmo/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/shenmo/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/shenmo/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/shenmo/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Echarts</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-10-27T13:24:00.000Z" title="Created 2023-10-27 21:24:00">2023-10-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-10-30T11:42:56.855Z" title="Updated 2023-10-30 19:42:56">2023-10-30</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/shenmo/categories/Echarts/">Echarts</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Echarts"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post Views:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Echarts"><a href="#Echarts" class="headerlink" title="Echarts"></a>Echarts</h1><h2 id="一、初始化项目"><a href="#一、初始化项目" class="headerlink" title="一、初始化项目"></a>一、初始化项目</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">    &lt;div id=&quot;main&quot;&gt;&lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script setup&gt;</span><br><span class="line">import * as echarts from &#x27;echarts&#x27;;</span><br><span class="line">import &#123; defineProps, ref,watch &#125; from &quot;vue&quot;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">const props = defineProps([&quot;formData&quot;])</span><br><span class="line">// console.log(props,&#x27;props&#x27;);</span><br><span class="line"></span><br><span class="line">const xData = ref([])</span><br><span class="line">const yData = ref([])</span><br><span class="line"></span><br><span class="line">watch(()=&gt;props.formData,(e,o) =&gt; &#123;</span><br><span class="line">    e.forEach(item =&gt; &#123;</span><br><span class="line">        xData.value.push(item.goods_name)</span><br><span class="line">        yData.value.push(item.count)</span><br><span class="line">    &#125;)</span><br><span class="line">    initData()</span><br><span class="line"></span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">const initData = () =&gt; &#123;</span><br><span class="line">    const main = document.getElementById(&#x27;main&#x27;)</span><br><span class="line">    var myChart = echarts.init(main);</span><br><span class="line">    // 绘制图表</span><br><span class="line">    const options = &#123;</span><br><span class="line">        title: &#123;</span><br><span class="line">            text: &#x27;热门资源&#x27;,</span><br><span class="line">            textStyle: &#123;</span><br><span class="line">                color: &#x27;#fff&#x27;,</span><br><span class="line">                fontSize: &#x27;12&#x27;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        tooltip: &#123;&#125;,</span><br><span class="line">        xAxis: &#123;</span><br><span class="line">            data: xData.value</span><br><span class="line">        &#125;,</span><br><span class="line">        yAxis: &#123;&#125;,</span><br><span class="line">        series: [</span><br><span class="line">            &#123;</span><br><span class="line">                name: &#x27;数量&#x27;,</span><br><span class="line">                type: &#x27;line&#x27;,</span><br><span class="line">                data: yData.value,</span><br><span class="line">                // radius : [&quot;10%&quot;,&quot;70%&quot;]</span><br><span class="line">            &#125;</span><br><span class="line">        ],</span><br><span class="line">        grid:&#123; // 让图表占满容器</span><br><span class="line">          top:&quot;30px&quot;,</span><br><span class="line">          left:&quot;30px&quot;,</span><br><span class="line">          right:&quot;20px&quot;,</span><br><span class="line">          bottom:&quot;20px&quot;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    myChart.setOption(options);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;</span><br><span class="line">#main &#123;</span><br><span class="line">    width: 100%;</span><br><span class="line">    height: 100%;</span><br><span class="line">    padding: 10px;</span><br><span class="line">&#125;</span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure>

<h2 id="二、基本配置"><a href="#二、基本配置" class="headerlink" title="二、基本配置"></a>二、基本配置</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="三、问题合集"><a href="#三、问题合集" class="headerlink" title="三、问题合集"></a>三、问题合集</h2><h3 id="1、DEPRECATED-‘normal’-hierarchy-in-itemStyle-has-been-removed-since-4-0-All-style-properties-are-configured-in-itemStyle-directly-now"><a href="#1、DEPRECATED-‘normal’-hierarchy-in-itemStyle-has-been-removed-since-4-0-All-style-properties-are-configured-in-itemStyle-directly-now" class="headerlink" title="1、DEPRECATED: ‘normal’ hierarchy in itemStyle has been removed since 4.0. All style properties are configured in itemStyle directly now."></a>1、DEPRECATED: ‘normal’ hierarchy in itemStyle has been removed since 4.0. All style properties are configured in itemStyle directly now.</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">itemStyle里的normal字段已被弃用</span><br><span class="line">//以前写法</span><br><span class="line">itemStyle: &#123;</span><br><span class="line">    normal: &#123;</span><br><span class="line">    color: &#x27;#fff&#x27;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//现在写法</span><br><span class="line">itemStyle: &#123;</span><br><span class="line">color: &#x27;#fff&#x27;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2、DEPRECATED-itemStyle-emphasis-has-been-changed-to-emphasis-itemStyle-since-4-0"><a href="#2、DEPRECATED-itemStyle-emphasis-has-been-changed-to-emphasis-itemStyle-since-4-0" class="headerlink" title="2、DEPRECATED: itemStyle.emphasis has been changed to emphasis.itemStyle since 4.0"></a>2、DEPRECATED: itemStyle.emphasis has been changed to emphasis.itemStyle since 4.0</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">echarts 弃用了itemStyle中包含emphasis</span><br><span class="line"></span><br><span class="line">同1</span><br></pre></td></tr></table></figure>

<h2 id="四、地图"><a href="#四、地图" class="headerlink" title="四、地图"></a>四、地图</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">    &lt;!-- &lt;div&gt; --&gt;</span><br><span class="line">        &lt;div class=&quot;china&quot; ref=&quot;china&quot; style=&quot;width: 100%;height: 100%;&quot;&gt;&lt;/div&gt;</span><br><span class="line">    &lt;!-- &lt;/div&gt; --&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script setup&gt;</span><br><span class="line">import * as echarts from &#x27;echarts&#x27;;</span><br><span class="line">import &#123; onMounted, ref,toRefs,watch &#125; from &quot;vue&quot;</span><br><span class="line">import chinaMap from &quot;@/assets/json/china.json&quot;</span><br><span class="line"></span><br><span class="line">onMounted(() =&gt; &#123;</span><br><span class="line">    setTimeout(()=&gt;&#123;</span><br><span class="line">    init()</span><br><span class="line">    &#125;,1000)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">const props = defineProps(&#123;</span><br><span class="line">    formData: &#123;</span><br><span class="line">        type: Object</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">const &#123; formData &#125; = toRefs(props)</span><br><span class="line">const china = ref()</span><br><span class="line"></span><br><span class="line">function init() &#123;</span><br><span class="line">    // 基于准备好的dom，初始化echarts实例</span><br><span class="line">    var myChart = echarts.init(china.value);</span><br><span class="line">    echarts.registerMap(&#x27;china&#x27;,chinaMap);</span><br><span class="line">    // 绘制图表</span><br><span class="line">    myChart.setOption(&#123;</span><br><span class="line">        //设置标题</span><br><span class="line">        title: &#123;</span><br><span class="line">            text: &#x27;用户分布&#x27;,</span><br><span class="line">            subtext: &#x27;&#x27;,</span><br><span class="line">            x: &#x27;left&#x27;,</span><br><span class="line">            color: &#x27;#fff&#x27;</span><br><span class="line">    &#125;,</span><br><span class="line">    tooltip: &#123;</span><br><span class="line">        trigger: &#x27;item&#x27;</span><br><span class="line">    &#125;,</span><br><span class="line">    visualMap: &#123;</span><br><span class="line">        show: true,</span><br><span class="line">        x: &#x27;left&#x27;,</span><br><span class="line">        y: &#x27;bottom&#x27;,</span><br><span class="line">        textStyle: &#123;</span><br><span class="line">            fontSize: 8,</span><br><span class="line">        &#125;,</span><br><span class="line">        //设置颜色比对条</span><br><span class="line">        splitList: [</span><br><span class="line">            &#123;start: 1, end: 9&#125;,</span><br><span class="line">            &#123;start: 10, end: 99&#125;,</span><br><span class="line">            &#123;start: 100, end: 999&#125;,</span><br><span class="line">            &#123;start: 1000, end: 9999&#125;,</span><br><span class="line">            &#123;start: 10000&#125;</span><br><span class="line">        ],</span><br><span class="line">        //颜色对比</span><br><span class="line">        color: [&#x27;yellow&#x27;, &#x27;blue&#x27;, &#x27;red&#x27;, &#x27;green&#x27;, &#x27;orange&#x27;]</span><br><span class="line">    &#125;,</span><br><span class="line">    //配置属性</span><br><span class="line">    series: [&#123;</span><br><span class="line">        name: &#x27;用户分布&#x27;,</span><br><span class="line">        type: &#x27;map&#x27;,</span><br><span class="line">        mapType: &#x27;china&#x27;,</span><br><span class="line">        roam: false,</span><br><span class="line">        selectedMode: false,                     //关闭点击区域背景变黄色</span><br><span class="line">        // emphasis: &#123;</span><br><span class="line">        //         borderWidth: .5,               //选中边线尺寸</span><br><span class="line">        //         borderColor: &#x27;#4b0082&#x27;,       //选中边线颜色</span><br><span class="line">        //         areaColor: &quot;#53899c&quot;,        //选中区域背景</span><br><span class="line">        //     &#125;,</span><br><span class="line">        //区域信息</span><br><span class="line">        itemStyle: &#123;</span><br><span class="line">            // normal: &#123;</span><br><span class="line">                borderWidth: 1,</span><br><span class="line">                borderColor: &quot;rgba(147, 235, 248, 1)&quot;,         //区域线条颜色</span><br><span class="line">                areaColor: &#123;</span><br><span class="line">                  type: &quot;radial&quot;,</span><br><span class="line">                  x: 0.5,</span><br><span class="line">                  y: 0.5,</span><br><span class="line">                  r: 0.8,</span><br><span class="line">                  colorStops: [</span><br><span class="line">                    &#123;</span><br><span class="line">                      offset: 0,</span><br><span class="line">                      color: &quot;rgba(147, 235, 248, 0)&quot;, // 0% 处的颜色</span><br><span class="line">                    &#125;,</span><br><span class="line">                    &#123;</span><br><span class="line">                      offset: 1,</span><br><span class="line">                      color: &quot;rgba(147, 235, 248, .2)&quot;, // 100% 处的颜色</span><br><span class="line">                    &#125;,</span><br><span class="line">                  ],</span><br><span class="line">                  globalCoord: false, // 缺省为 false</span><br><span class="line">                &#125;,</span><br><span class="line">                shadowColor: &quot;rgba(128, 217, 248, 1)&quot;,</span><br><span class="line">                shadowOffsetX: -2,</span><br><span class="line">                shadowOffsetY: 2,</span><br><span class="line">                shadowBlur: 10,</span><br><span class="line">                emphasis: &#123;</span><br><span class="line">                  areaColor: &quot;#389BB7&quot;,</span><br><span class="line">                  borderWidth: 0,</span><br><span class="line">                &#125;,</span><br><span class="line">        &#125;,</span><br><span class="line">        label: &#123;</span><br><span class="line">                show: true,</span><br><span class="line">                fontSize: 12,</span><br><span class="line">                color: &#x27;#fff&#x27;,            //文字颜色</span><br><span class="line">            </span><br><span class="line">        &#125;,</span><br><span class="line">        data: formData.value</span><br><span class="line">        // data: [</span><br><span class="line">        //     &#123;name:&#x27;北京&#x27;,value:8&#125;,</span><br><span class="line">        //     &#123;name:&#x27;上海&#x27;,value:88&#125;,</span><br><span class="line">        //     &#123;name:&#x27;甘肃&#x27;,value:888&#125;,</span><br><span class="line">        //     &#123;name:&#x27;海南&#x27;,value:8888&#125;,</span><br><span class="line">        //     &#123;name:&#x27;新疆&#x27;,value:88888&#125;,</span><br><span class="line">        //     &#123;name:&#x27;重庆&#x27;,value:88888&#125;,</span><br><span class="line">        //     &#123;name:&#x27;西藏&#x27;,value:8888&#125;,</span><br><span class="line">        //     &#123;name:&#x27;浙江&#x27;,value:88888&#125;,</span><br><span class="line">        //     &#123;name:&#x27;湖南&#x27;,value:88888&#125;,</span><br><span class="line">        //     &#123;name:&#x27;黑龙江&#x27;,value:888&#125;,</span><br><span class="line">        // ]</span><br><span class="line">    &#125;]</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// watch(()=&gt;formData.value, (o,m) =&gt; &#123;</span><br><span class="line">//   console.log(o);</span><br><span class="line">// &#125;)</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;</span><br><span class="line"></span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure>

<h2 id="五、饼状图"><a href="#五、饼状图" class="headerlink" title="五、饼状图"></a>五、饼状图</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">    &lt;div id=&quot;lineId&quot;&gt;&lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script setup&gt;</span><br><span class="line">import * as echarts from &#x27;echarts&#x27;;</span><br><span class="line">import &#123; defineProps, ref,watch,onMounted &#125; from &quot;vue&quot;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">const props = defineProps(&#123;</span><br><span class="line">    formData: &#123;</span><br><span class="line">        type: Object</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line">// console.log(props,&#x27;line&#x27;);</span><br><span class="line"></span><br><span class="line">// const xData = ref([])</span><br><span class="line">// const yData = ref([])</span><br><span class="line"></span><br><span class="line">watch(()=&gt;props.formData,(e,o) =&gt; &#123;</span><br><span class="line">    // e.forEach(item =&gt; &#123;</span><br><span class="line">    //     xData.value.push(item.title)</span><br><span class="line">    //     yData.value.push(item.count)</span><br><span class="line">    // &#125;)</span><br><span class="line">    initData()</span><br><span class="line"></span><br><span class="line">&#125;)</span><br><span class="line">onMounted(()=&gt;&#123;</span><br><span class="line">    setTimeout(()=&gt;&#123;</span><br><span class="line">        initData()</span><br><span class="line">    &#125;,1000)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">const initData = () =&gt; &#123;</span><br><span class="line">    const main = document.getElementById(&#x27;lineId&#x27;)</span><br><span class="line">    var myChart = echarts.init(main);</span><br><span class="line">    // 绘制图表</span><br><span class="line">    const options = &#123;</span><br><span class="line">        title: &#123;</span><br><span class="line">            text: &#x27;热门分类&#x27;,</span><br><span class="line">            textStyle: &#123;</span><br><span class="line">                color: &#x27;#fff&#x27;,</span><br><span class="line">                fontSize: &#x27;14&#x27;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        tooltip: &#123;&#125;,</span><br><span class="line">        // xAxis: &#123;</span><br><span class="line">        //     data: xData.value</span><br><span class="line">        // &#125;,</span><br><span class="line">        // yAxis: &#123;&#125;,</span><br><span class="line">        series: [</span><br><span class="line">            &#123;</span><br><span class="line">                name: &#x27;数量&#x27;,</span><br><span class="line">                type: &#x27;pie&#x27;,</span><br><span class="line">                data: props.formData,</span><br><span class="line">                radius: &#x27;55%&#x27;,               //饼状图尺寸</span><br><span class="line">            &#125;</span><br><span class="line">        ],</span><br><span class="line">        grid:&#123; // 让图表占满容器</span><br><span class="line">            top:&quot;50px&quot;,</span><br><span class="line">            left:&quot;50px&quot;,</span><br><span class="line">            right:&quot;50px&quot;,</span><br><span class="line">            bottom:&quot;20px&quot;</span><br><span class="line">            &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    myChart.setOption(options);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;</span><br><span class="line">#lineId &#123;</span><br><span class="line">    width: 100%;</span><br><span class="line">    height: 100%;</span><br><span class="line">&#125;</span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>Author: </span><span class="post-copyright-info"><a href="https://gitee.com/trial-street/shenmo.git">审陌</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>Link: </span><span class="post-copyright-info"><a href="https://gitee.com/trial-street/shenmo.git/2023/10/27/echarts/">https://gitee.com/trial-street/shenmo.git/2023/10/27/echarts/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/shenmo/tags/Echarts/">Echarts</a></div><div class="post_share"><div class="social-share" data-image="/shenmo/img/echarts.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/shenmo/2023/10/27/css/" title="CSS 案例合集"><img class="cover" src="/shenmo/img/css.png" onerror="onerror=null;src='/shenmo/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous</div><div class="prev_info">CSS 案例合集</div></div></a></div><div class="next-post pull-right"><a href="/shenmo/2023/10/27/js/" title="JS API合集"><img class="cover" src="/shenmo/img/js.png" onerror="onerror=null;src='/shenmo/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">Next</div><div class="next_info">JS API合集</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/shenmo/img/fluid.png" onerror="this.onerror=null;this.src='/shenmo/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">审陌</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/shenmo/archives/"><div class="headline">Articles</div><div class="length-num">19</div></a><a href="/shenmo/tags/"><div class="headline">Tags</div><div class="length-num">19</div></a><a href="/shenmo/categories/"><div class="headline">Categories</div><div class="length-num">17</div></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Contents</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Echarts"><span class="toc-number">1.</span> <span class="toc-text">Echarts</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%88%9D%E5%A7%8B%E5%8C%96%E9%A1%B9%E7%9B%AE"><span class="toc-number">1.1.</span> <span class="toc-text">一、初始化项目</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE"><span class="toc-number">1.2.</span> <span class="toc-text">二、基本配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E9%97%AE%E9%A2%98%E5%90%88%E9%9B%86"><span class="toc-number">1.3.</span> <span class="toc-text">三、问题合集</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81DEPRECATED-%E2%80%98normal%E2%80%99-hierarchy-in-itemStyle-has-been-removed-since-4-0-All-style-properties-are-configured-in-itemStyle-directly-now"><span class="toc-number">1.3.1.</span> <span class="toc-text">1、DEPRECATED: ‘normal’ hierarchy in itemStyle has been removed since 4.0. All style properties are configured in itemStyle directly now.</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81DEPRECATED-itemStyle-emphasis-has-been-changed-to-emphasis-itemStyle-since-4-0"><span class="toc-number">1.3.2.</span> <span class="toc-text">2、DEPRECATED: itemStyle.emphasis has been changed to emphasis.itemStyle since 4.0</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E5%9C%B0%E5%9B%BE"><span class="toc-number">1.4.</span> <span class="toc-text">四、地图</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%94%E3%80%81%E9%A5%BC%E7%8A%B6%E5%9B%BE"><span class="toc-number">1.5.</span> <span class="toc-text">五、饼状图</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/shenmo/2023/10/30/flySearch/" title="ButterFly 主题"><img src="/shenmo/img/butterfly.png" onerror="this.onerror=null;this.src='/shenmo/img/404.jpg'" alt="ButterFly 主题"/></a><div class="content"><a class="title" href="/shenmo/2023/10/30/flySearch/" title="ButterFly 主题">ButterFly 主题</a><time datetime="2023-10-30T13:24:00.000Z" title="Created 2023-10-30 21:24:00">2023-10-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/shenmo/2023/10/27/css/" title="CSS 案例合集"><img src="/shenmo/img/css.png" onerror="this.onerror=null;this.src='/shenmo/img/404.jpg'" alt="CSS 案例合集"/></a><div class="content"><a class="title" href="/shenmo/2023/10/27/css/" title="CSS 案例合集">CSS 案例合集</a><time datetime="2023-10-27T13:24:00.000Z" title="Created 2023-10-27 21:24:00">2023-10-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/shenmo/2023/10/27/echarts/" title="Echarts"><img src="/shenmo/img/echarts.png" onerror="this.onerror=null;this.src='/shenmo/img/404.jpg'" alt="Echarts"/></a><div class="content"><a class="title" href="/shenmo/2023/10/27/echarts/" title="Echarts">Echarts</a><time datetime="2023-10-27T13:24:00.000Z" title="Created 2023-10-27 21:24:00">2023-10-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/shenmo/2023/10/27/js/" title="JS API合集"><img src="/shenmo/img/js.png" onerror="this.onerror=null;this.src='/shenmo/img/404.jpg'" alt="JS API合集"/></a><div class="content"><a class="title" href="/shenmo/2023/10/27/js/" title="JS API合集">JS API合集</a><time datetime="2023-10-27T13:24:00.000Z" title="Created 2023-10-27 21:24:00">2023-10-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/shenmo/2023/10/27/vue3count/" title="vue3 问题合集"><img src="/shenmo/img/vue3.png" onerror="this.onerror=null;this.src='/shenmo/img/404.jpg'" alt="vue3 问题合集"/></a><div class="content"><a class="title" href="/shenmo/2023/10/27/vue3count/" title="vue3 问题合集">vue3 问题合集</a><time datetime="2023-10-27T13:24:00.000Z" title="Created 2023-10-27 21:24:00">2023-10-27</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 审陌</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Toggle Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between Single-column and Double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/shenmo/js/utils.js"></script><script src="/shenmo/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">Search</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  Loading the Database</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="Search for Posts" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/shenmo/js/search/local-search.js"></script></div></div></body></html>